<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <%@ include file="/main/main_css.jsp" %>
    <%@ include file="/main/main_js.jsp" %>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>身份证</title>
    <script src="JS/IDCard.js"></script>
    <script src="JS/Sound.js"></script>
    <script src="JS/main.js"></script>
    <script src="static/js/public.js"></script>
    <script src="static/js/idreader.js"></script>
  </head>
  
  <body>
    <!--  -->
    <div class="all-wrapper">
        <div class="row com-header text-center">
            <span>鹰潭市行政服务中心</span>
        </div>
        <div class="row main-content take-photos">
            <div class="col-md-24" >
                <div class="time-count pull-right">
                    <span>剩余</span>
                    <span id="time" class="text-red"></span>
                    <span>秒</span>
                </div>
            </div>
            <div class="col-md-24">
                <h1>登录</h1>
            </div>
            <div class="col-md-24 card-wp">
                <div class="card-com">
                    <span class="tip">请将身份证置于身份证扫描区（如图所示）</span>
                    <div class="image-wrapper">
                        <img src="static\image\cards\card.png" alt="">
                    </div>
                </div>
            </div>
        </div>
        <div class="row footer">
            <button id="prvIndex" class="btn btn-success btn-lg" role="button"><i class="fa fa-reply"></i>返回首页</button>
        </div>
    </div>
    <!-- 存储身份证读取到的信息 -->
    <form id="userLogin" action="login" method="post">
    	<input type="hidden" id="address" name="address"/>
    	<input type="hidden" id="birthday" name="birthday"/>
    	<input type="hidden" id="fpName" name="fpName"/>
    	<input type="hidden" id="grantdept" name="grantdept"/>
    	<!-- <input type="hidden" id="idCard" name="idCard" value="410482199404164452"/> -->
    	<input type="hidden" id="idCard" name="idCard" value="422202199107057512"/>
    	<input type="hidden" id="idImg" name="idImg"/>
    	<input type="hidden" id="realName" name="realName" value="啊啊啊"/>
    	<input type="hidden" id="ethnic" name="ethnic"/>
    	<input type="hidden" id="sex" name="sex"/>
    	<input type="hidden" id="userLifeBegin"/>
    	<input type="hidden" id="userLifeEnd"/>
    	<input type="hidden" id="service" name="service" value="${user.service}"/>
    </form>
    <form id="loginOut" action="loginOut"></form>
    <script>
    	function onPageLoad(){
    		countdown();
    		exitIdCard();
    		soundIdCard();
    		window.setTimeout("openIdCard()", 3000);
    	}
    	 
    	var count = 59;
    	function countdown(){
    		$("#time").text(count);
    		if(count > 0){
    			window.setTimeout("countdown()",1000);
    			count --;
    		}else{
    			//关闭硬件
    			exitIdCard();
    			//跳转到首页
    			//$("#userLogin").submit();
    			$("#loginOut").submit();
    		}
    	}
    	
    	//语音播报身份证识别
    	function soundIdCard(){
    		sound_speak("请将二代身份证置于识别区");
    	}
    	
    	//开启硬件
    	function openIdCard(){
    		send_command(
    				"idReaderReadInfo",			//读取身份证方法名
    			    "nothing",	
    			    function (json) {
    					var data = JSON.parse(json);
    					if(data.status == 100){
    						$("#address").val(data.address);//地址
        					$("#birthday").val(data.birthday);//生日
        					$("#fpName").val(data.fpName);//指纹信息（较新的身份证存储有指纹信息）
        					$("#grantdept").val(data.grantdept);//签发地
        					$("#idCard").val(data.idCardNo);//身份证号
        					$("#idImg").val(data.idImg);//身份证照片的base64格式字符串
        					$("#realName").val(data.name);//姓名
        					$("#ethnic").val(data.nation);//民族
        					$("#sex").val(data.sex == "男" ? "0" : "1");//性别
        					$("#userLifeBegin").val(data.userLifeBegin);//有效起始时间
        					$("#userLifeEnd").val(data.userLifeEnd);//有效截至时间
        					$("#userLogin").submit();
        					exitIdCard();//关闭硬件
    					}else if(data.status == 200){
    						layer.alert("身份证识别失败,请重新识别");
    					}else if(data.status == 300){
    						layer.alert("当前模块未启用,请联系管理员");
    					}
    				}
    		);
    	}
    	
    	//关闭硬件
    	function exitIdCard(){
    		send_command(
    			    "stopRead",
    			    "nothing",
    			    function (json) {
    			    	var data = JSON.parse(json);
    			    	if(data.status == "200"){
    						layer.alert("关闭失败");
    					}else if(data.status == "300"){
    						layer.alert("当前模块未启用");
    					}
    			    });
    	}
    	
    	//返回首页
    	$("#prvIndex").on("click",function(){
    		exitIdCard();
    		//跳转到首页
			$("#loginOut").submit();
    	});
    	
    	onPageLoad();
    	
    	var winH = $(document).height();
	    var mainH = winH -170;
	    $('.main-content').height(mainH);
    </script>
  </body>
</html>
